package com.fbs.wowo.manage.web;


import com.fbs.wowo.base.BaseController;
import com.fbs.wowo.base.Response;
import com.fbs.wowo.manage.entity.AccountDetail;
import com.fbs.wowo.manage.service.AccountDetailService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 实名认证
 */
@RestController
@RequestMapping("/cert")
public class CertificationController extends BaseController {

    /**
     * 实名认证
     * 绑定微信
     * 交易密码
     * @param userId
     * @return
     */
    @GetMapping("/cbwpp")
    public Response certBindWxPayPass(String userId) {
        accountDetailService.certBindWxPayPass(userId);
        return success();
    }
    /**
     * 添加认证
     *
     * @param ad
     * @return
     */
    @PostMapping("/save")
    public Response insertCertification(AccountDetail ad) {
        accountDetailService.cert(ad);
        return success();
    }

    /**
     * 查询认证信息
     *
     * @param userId
     * @return
     */
    @GetMapping("/cert")
    public Response findUserId(String userId) {
        AccountDetail ad = accountDetailService.findByUserId(userId);
        if (ad != null) {
            if (ad.getCertStatus() == 1) {
                return success(1);
            } else if (ad.getCertStatus() == 2) {
                return success(2);
            } else {
                return success(0);
            }
        } else {
            return success(0);
        }
    }

    /**
     * 更新认证信息
     *
     * @param ad
     * @return
     */
    //@PostMapping("/modify")
    public Response modifyCert(AccountDetail ad) {
        accountDetailService.modify(ad);
        return success();
    }

    /**
     * 审核中的列表
     *
     * @return
     */
    @GetMapping("/find")
    public Response findInReviewList(@RequestParam(defaultValue = "1") int pageNum,@RequestParam(defaultValue = "10") int pageSize,String type) {
        PageHelper.startPage(pageNum, pageSize);
        List<AccountDetail> inReviewList = accountDetailService.findInReviewList(type);
        PageInfo<AccountDetail> pageInfo = new PageInfo<>(inReviewList);
        return success(pageInfo);
    }


    /**
     * 审核
     * @return
     */
    @PostMapping("/audit")
    public Response updateAuditState(String userId,int state) {
        return success(accountDetailService.updateAuditState(userId,state));
    }



    @Resource
    private AccountDetailService accountDetailService;
}
